package org.kl.auditsupervision.service.fnd;

 

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.kl.auditsupervision.entity.fnd.SjJy;
import org.kl.auditsupervision.repository.fnd.SjJyDao;
import org.kl.bf.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.utils.Collections3;

import com.alibaba.fastjson.JSON;
 
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional
public class SjJyService extends BasicService<SjJy> {
	@Autowired
	private SjJyDao sjJyDao;
	
	public List<SjJy> findBySjFxId(String sjFxId){
		return sjJyDao.findBySjFxId(sjFxId);
	}
	
	public void save(SjJy entity, @RequestParam(value = "inserted") String detailInserted,
			@RequestParam(value = "updated") String detailUpdated, @RequestParam(value = "deleted") String detailDeleted) {
		sjJyDao.save(entity);
		if (StringUtils.isNotBlank(detailInserted)) {
			List<SjJy> inserts = JSON.parseArray(detailInserted, SjJy.class);
			if (Collections3.isNotEmpty(inserts)) {
				for (SjJy a : inserts) {
					// 增加与主表相关的数据复制代码
					sjJyDao.save(a);
				}
			}
		}
		if (StringUtils.isNotBlank(detailUpdated)) {
			List<SjJy> updates = JSON.parseArray(detailUpdated, SjJy.class);
			if (Collections3.isNotEmpty(updates)) {
				for (SjJy b : updates) {
					sjJyDao.save(b);
				}
			}
		}
		if (StringUtils.isNotBlank(detailDeleted)) {
			List<SjJy> deletes = JSON.parseArray(detailDeleted, SjJy.class);
			if (Collections3.isNotEmpty(deletes)) {
				sjJyDao.delete(deletes);
			}
		}
	}
}
